<?php 
namespace Home\Controller;
use Think\Controller;
class RecharController extends Controller{

	//确认充值信息
	public function relacz()
	{	
			
		//展示充值信息  获取用户  name /id  money
		$userinfo['id'] = session('userid');
		$userinfo['name'] = session('username');
		$userinfo['money'] = $_POST['money'];

		$this->assign('userinfo',$userinfo);
		$this->display();

	}

	##  餐币 充值 积分 充值  
	public function czadd()
	{
		if(IS_POST)
		{
			//信息收集			
			$data = array();
			$uid = session('userid');
			$data['userid'] = $uid;
			$data['cmoney']	= $_POST['cmoney'];
			$data['mold']	= $_POST['mold'];
			$data['uid']	= session('userid');
			$data['pubtime'] = time();
			$data['status'] = 1;

			//将数据写入表
			$recharModel = D('Recharge');
			$userModel = D('User');
			$user = $userModel->where(array('uid'=>$uid))->find();
			
			$rec = $recharModel->create($data);
			$rec = $recharModel->where(array('uid'=>$uid))->add();
			if($rec)
			{	
				//将用户表内对应的用户积分或金额增加

				//积分增加
				if($data['mold']=='充积分')
				{
					$userModel->potios += $data['cmoney'];
					$userinfo = $userModel->where(array('uid'=>$uid))->save();
					if($userinfo)
					{
						$this->success('充值成功',U('home/user/grzl'),2);
					}
					
				}
				//餐币增加
				if($data['mold']=='充餐币')
				{
					$userModel->money += $data['cmoney'];
					$userminfo = $userModel->where(array('uid'=>$uid))->save();
					if($userminfo)
					{
						$this->success('充值成功',U('home/user/grzl'),2);
					}
					
				}
				
			}
			else
			{
				$this->error('充值失败','home/user/cz',array('uid'=>$data['userid']),2);
			}

		}
		else
		{

		}
	}


}


?>